﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using Game.Foundation;
using Bruce.Net;
using System.Diagnostics;

namespace Server.Major
{
    class Program
    {

        public static Dictionary<string, GameConfig> m_gameDict = new Dictionary<string, GameConfig>();

        static void Main(string[] args)
        {
            GameServerDispatcher gameServerDispatcher = new GameServerDispatcher();
            ServerSocket gameServer = new ServerSocket(10087, 100, PacketLoader.Default, gameServerDispatcher);
            gameServer.SessionDisconnected += (sender, e) =>
            {
                ISession session = (ISession)sender;
                if (session != null)
                {
                    GameConfig game = session.GetRelationData<GameConfig>();
                    if (game != null)
                    {
                        Packet logout = new Packet((int)PacketType.注销游戏处理程序);
                        logout.WriteString(game.Name);
                        gameServerDispatcher.Produce(logout);
                    }
                    else
                    {
                        Console.WriteLine("game is null.");
                    }
                }
                else
                {
                    Console.WriteLine("session is null.");
                }
            };
            gameServer.Listen();
            gameServerDispatcher.Loop();

            ClientDispatcher clientDispatcher = new ClientDispatcher();
            ServerSocket clietnServer = new ServerSocket(10086, 100, PacketLoader.Default, clientDispatcher);
            clietnServer.Listen();
            clientDispatcher.Loop();

            Console.ReadLine();
        }
    }
}
